/*
 * FileName：SysRoleCtrl.java 
 * <p>
 * Copyright (c) 2017-2020, <a href="http://www.webcsn.com">hermit (1154808491@qq.com)</a>.
 * <p>
 * Licensed under the GNU General Public License, Version 3 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.gnu.org/licenses/gpl-3.0.html
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package com.smart.primary.sys.ctrl;


import java.util.List;

import com.smart.primary.common.common.BaseCtrl;
import com.smart.primary.common.util.AjaxResult;
import com.smart.primary.sys.service.RoleService;
import com.smart.primary.sys.vo.Res;
import com.smart.primary.sys.vo.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
* 角色信息表 Controller层
*
* @author hermit
* @date 2018-02-23 11:02:18
*/
@Controller
@RequestMapping("/sys/role")
public class RoleCtrl extends BaseCtrl {

	@Autowired
	private RoleService sysRoleService;

	/**
	* 获取页面分页数据集合
	*
	* @author hermit
	* @date 2018-02-23 11:02:18
	* @param sysRole
	* @return
	*/
	@RequestMapping("/list")
	@ResponseBody
	public AjaxResult list(Role sysRole)
		throws Exception{
		List<Role> list = sysRoleService.queryListByPage(sysRole);
		return getResult(sysRole,list);
	}

	/**
	* 数据保存(新增或修改)
	*
	* @author hermit
	* @date 2018-02-23 11:02:18
	* @param sysRole
	* @return
	*/
	@RequestMapping("/save")
	@ResponseBody
	public AjaxResult save(Role sysRole)
		throws Exception{

		return this.sysRoleService.saveOrUpdate(sysRole,request,response);
	}

	/**
	* 数据删除
	*
	* @author hermit
	* @date 2018-02-23 11:02:18
	* @param sysRole
	* @return
	*/
	@RequestMapping("/delete")
	@ResponseBody
	public AjaxResult delete(Role sysRole)
		throws Exception{
		sysRoleService.delete(sysRole.getRoleId());
		return AjaxResult.deleteSuccess();
	}

	/**
	 * 获取菜单列表
	 *
	 * @author hermit
	 * @date 2018-02-23 11:02:18
	 * @param sysRes
	 * @return
	 */
	@RequestMapping("/getResList")
	@ResponseBody
	public AjaxResult getResList(Res sysRes, String roleId)
			throws Exception{

		List<Object> resList = this.sysRoleService.getResListTree(sysRes,roleId);
		return AjaxResult.success(resList);
	}
	/**
	 * 角色授权
	 *
	 * @author hermit
	 * @date 2018-02-23 11:02:18
	 * @param roleId 角色ID
	 * @param resIds 资源ID  （逗号分隔）
	 * @return
	 */
	@RequestMapping("/authorization")
	@ResponseBody
	public AjaxResult authorization(String roleId,String resIds)
			throws Exception{

		this.sysRoleService.authorizationToRole(roleId,resIds);
		return AjaxResult.success();
	}

}
